package com.atguigu.yygh.hosp.controller.api;

import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.hosp.service.DepartmentService;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.hosp.service.HospitalSetService;
import com.atguigu.yygh.hosp.service.ScheduleService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.DepartmentVo;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import com.atguigu.yygh.vo.hosp.ScheduleOrderVo;
import com.atguigu.yygh.vo.order.SignInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ybl
 * @version 1.9
 * @date 2021/5/19 19:57
 */
@Api(tags = "医院管理接口")
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospitalApiController {

  @Autowired
  private HospitalService hospitalService;

  @Autowired
  private DepartmentService departmentService;

  @Autowired
  private ScheduleService scheduleService;

  @Autowired
  private HospitalSetService hospitalSetService;

  // 获取医院签名信息
  @ApiOperation(value = "获取医院签名信息")
  @GetMapping("inner/getSignInfoVo/{hoscode}")
  public SignInfoVo getSignInfoVo(
      @ApiParam(name = "hoscode", value = "医院code", required = true)
      @PathVariable("hoscode") String hoscode) {
    return hospitalSetService.getSignInfoVo(hoscode);
  }


  // 根据排班id获取预约下单数据
  @ApiOperation(value = "根据排班id获取预约下单数据")
  @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
  public ScheduleOrderVo getScheduleOrderVo(
      @ApiParam(name = "scheduleId", value = "排班id", required = true)
      @PathVariable("scheduleId") String scheduleId) {
    return scheduleService.getScheduleOrderVo(scheduleId);
  }

  // 根据排班id获取排班数据
  @ApiOperation(value = "根据排班id获取排班数据")
  @GetMapping("getSchedule/{scheduleId}")
  public Result getSchedule(@PathVariable String scheduleId){
    return Result.ok(scheduleService.getSchedule(scheduleId));
  }

  //获取可预约排班数据
  @ApiOperation(value = "获取可预约排班数据")
  @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
  public Result getBookingSchedule(@PathVariable Integer page,
                                   @PathVariable Integer limit,
                                   @PathVariable String hoscode,
                                   @PathVariable String depcode){
    return Result.ok(scheduleService.getBookingScheduleRule(page,limit,hoscode,depcode));
  }

  // 获取排班数据
  @ApiOperation(value = "获取排班数据")
  @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
  public Result findScheduleList(@ApiParam(name = "hoscode", value = "医院code", required = true)
                                   @PathVariable String hoscode,
                                 @ApiParam(name = "depcode", value = "科室code", required = true)
                                   @PathVariable String depcode,
                                 @ApiParam(name = "workDate", value = "排班日期", required = true)
                                   @PathVariable String workDate){
    return Result.ok(scheduleService.getDetailSchedule(hoscode, depcode, workDate));
  }



  // 获取科室列表
  @ApiOperation(value = "获取科室列表")
  @GetMapping("department/{hoscode}")
  public Result index(@PathVariable String hoscode){
    List<DepartmentVo> deptTree = departmentService.getDeptTree(hoscode);
    return Result.ok(deptTree);
  }

  //医院预约挂号详情
  @ApiOperation(value = "医院预约挂号详情")
  @GetMapping("{hoscode}")
  public Result item(@PathVariable String hoscode){
    return Result.ok(hospitalService.item(hoscode));
  }

  @ApiOperation(value = "获取分页列表")
  @GetMapping("{page}/{limit}")
  public Result index(@PathVariable Integer page,
                      @PathVariable Integer limit,
                      HospitalQueryVo hospitalQueryVo) {
    // 显示上线的医院
    // hospitalQueryVo.setStatus(1);
    Page<Hospital> hospitalPage = hospitalService.findHospitalPage(page, limit, hospitalQueryVo);
    return Result.ok(hospitalPage);
  }

  // 根据医院名称关键字搜索医院列表
  @ApiOperation(value = "根据医院名称关键字搜索医院列表")
  @GetMapping("findByHosName/{hosName}")
  public Result findByHosName(@PathVariable("hosName") String hosName){
    List<Hospital> list = hospitalService.findByHosName(hosName);
    return Result.ok(list);
  }

}
